package com.omg.api.entry;

import javax.servlet.http.HttpServletRequest;

import com.omg.api.argument.Argument;
import com.omg.api.argument.RegisterArgument;
import com.omg.api.handle.RegisterHandler;
import com.omg.constant.ResponseCode;

public class register extends Entry {

	private static final long serialVersionUID = 1L;

	public register() {
		super(false);
	}

	@Override
	protected Argument fetchArgument(HttpServletRequest request)
			throws Exception {

		// email
		String email = request.getParameter("email");

		if (email == null || email.isEmpty()) {
			throw new Exception("" + ResponseCode.AP_E_Info_EmailInvalid);
		}

		// passwd
		String passwd = request.getParameter("passwd");
		if (passwd == null || passwd.isEmpty()) {
			throw new Exception("" + ResponseCode.AP_E_Info_PasswordMissing);
		}

		// nickname
		String nickname = request.getParameter("nickname");
		if (nickname == null || nickname.isEmpty()) {
			throw new Exception("" + ResponseCode.AP_E_Info_NickNameMissing);
		}

		RegisterArgument argument = new RegisterArgument();
		argument.setEmail(email);
		argument.setPasswd(passwd);
		argument.setNickname(nickname);

		return argument;
	}

	@Override
	protected String getResult(Argument argument) throws Exception {
		return RegisterHandler.getInstance().handle(argument);
	}

}
